package com.sparrows.pirates.model;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.sparrows.pirates.helpers.Animator;

public class CannonFireSmoke {
	
	private Vector2 position;
	private Animator anim;
	private float angle;
	
	public CannonFireSmoke(Vector2 position, float angle, TextureRegion texture, int numFrames, int frameSizeX, int frameSizeY, float frameSpeed){
		this.position = position;
		this.angle = angle;
		//Divide the texture into 7 regions
		TextureRegion[][] tmp = texture.split(frameSizeX, frameSizeY);
		TextureRegion[] tmp2 = new TextureRegion[numFrames];
		for (int i=0; i < numFrames; i++){
			tmp2[i] = tmp[0][i];
		}
		//Animator class takes the frame rate, an array of texture regions, number of frames, and whether or not it should loop
		this.anim = new Animator(frameSpeed, tmp2, numFrames, false);	
	}
	
	public boolean update(float dt){
		this.anim.update(dt);
		
		if (this.anim.getCurrentFrame() >= this.anim.getNumFrames()){
			return true;
		} else {
			return false;
		}
	}
	
	public void draw(SpriteBatch batch){
		this.anim.draw(batch, this.position.x, this.position.y, 1, 1, this.angle);
	}

}
